CREATE OR REPLACE FUNCTION set_value(TEXT, TEXT) RETURNS void AS $$
BEGIN
    
    CREATE TEMP TABLE IF NOT EXISTS session_variables (
      key   TEXT NOT NULL PRIMARY KEY,
      value TEXT
    );

  IF get_value($1) IS NULL THEN
    INSERT INTO session_variables (key, value) VALUES($1, $2);
  ELSE
    UPDATE session_variables SET value = $2 WHERE key = $1;
  END IF;

  RETURN;
END;
$$ LANGUAGE plpgsql;
COMMENT ON FUNCTION set_value(TEXT, TEXT) IS
'Create/Assign value to a new/existing session variable';